﻿using System.Collections.Generic;
using System.Windows.Controls;
using System.Collections;
using Kiva7.Controls;
using Kiva7.ViewModels;
using Kiva7.DataClasses;
using System.Collections.ObjectModel;

namespace Kiva7.Pages
{
    public partial class LoansControl : BaseUserControl
    {
        public LoansControl()
        {
            InitializeComponent();
        }

        public void SetBindingList(IEnumerable itemsSource)
        {
            lbxLoans.ItemsSource = itemsSource;
        }

        private void lbxLoans_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Loan model = lbxLoans.SelectedItem as Loan;
            if (model == null)
            {
                return;
            }
            if (lbxLoans.ItemsSource is LoanViewModelCollection)
            {
                DoNavigate(LoanDetailPage.GetPageUrl(lbxLoans.ItemsSource as LoanViewModelCollection, lbxLoans.SelectedIndex));
            }
            else if (lbxLoans.ItemsSource is LoanList)
            {
                DoNavigate(LoanDetailPage.GetPageUrl(lbxLoans.ItemsSource as LoanList, lbxLoans.SelectedIndex));
            }
            else if (lbxLoans.ItemsSource is List<Loan>)
            {
                DoNavigate(LoanDetailPage.GetPageUrl(lbxLoans.ItemsSource as List<Loan>, lbxLoans.SelectedIndex));
            }

            lbxLoans.SelectedItem = null;
        }

    }
}
